package com.yk.customlive.three;

import android.app.job.JobInfo;
import android.app.job.JobParameters;
import android.app.job.JobScheduler;
import android.app.job.JobService;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.util.Log;


public class KeepLiveWorkService extends JobService {


    @Override
    public void onCreate() {
        super.onCreate();
        startJob(this);
    }

    @Override
    public boolean onStartJob(JobParameters jobParameters) {
        Log.e("YKLOG","KeepLiveWorkService--onStartJob");
        return false;

    }

    @Override
    public boolean onStopJob(JobParameters jobParameters) {
        Log.e("YKLOG","KeepLiveWorkService--onStopJob");
        return false;
    }


    public static void startJob(Context context) {
        JobScheduler jobScheduler = (JobScheduler) context.getSystemService(JOB_SCHEDULER_SERVICE);
        JobInfo.Builder builder = new JobInfo.Builder(27,
                new ComponentName(context.getPackageName(), KeepLiveWorkService.class.getName()))
                .setPersisted(true);
        if (Build.VERSION.SDK_INT<Build.VERSION_CODES.N){
            builder.setPeriodic(1000);
        }else {
            builder.setMinimumLatency(1000);
        }
        assert jobScheduler != null;
        jobScheduler.schedule(builder.build());

    }

}
